package com.tarena.lbs.message.web.rpc;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tarena.lbs.message.api.TriggerMessageApi;
import com.tarena.lbs.message.web.mq.NoticeProducer;
import com.tarena.lbs.pojo.message.param.TriggerMessageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TriggerMessageApiImpl implements TriggerMessageApi {

    @Autowired
    private NoticeProducer noticeProducer;

    /**
     * 发送触发消息
     *
     * @param triggerMessageParam 触发消息参数
     * @return 发送结果
     * @throws JsonProcessingException JSON处理异常
     */
    @Override
    public boolean sendMessage(TriggerMessageParam triggerMessageParam) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        String jsonString = objectMapper.writeValueAsString(triggerMessageParam);
        // 用stream发消息队列
        noticeProducer.sendMsg(jsonString);
        return true;
    }
}